************************************************
*We construct now the 58 strata of BASM
************************************************
gen j=.

*1. Loreto, Ucayali, Madre de Dios 
replace j=1 if idepa==16 
replace j=1 if idepa==25 
replace j=1 if idepa==17 

*2. Callao
replace j=2 if idepa==7

*3. Ancash (Bolognesi,Ocros)
replace j=3 if idepa==2 & iprov==5 
replace j=3 if idepa==2 & iprov==14 

*4. Ancash (Huaraz, Huaylas, Mariscal Luzuriaga, Pallasca, Santa, Sihuas, Pomabamba, Recuay, Asuncion, Carhuaz, Aija, Antonio Raymondi, Carlos F. Fitzcarrald, Huari, Huarmey, Casma, Corongo, Yungay)
*replace j=4 if idepa==2 & j~=3
replace j=4 if idepa==2 & iprov==1
replace j=4 if idepa==2 & iprov==2
replace j=4 if idepa==2 & iprov==3
replace j=4 if idepa==2 & iprov==4
replace j=4 if idepa==2 & iprov==6
replace j=4 if idepa==2 & iprov==7
replace j=4 if idepa==2 & iprov==8
replace j=4 if idepa==2 & iprov==9
replace j=4 if idepa==2 & iprov==10
replace j=4 if idepa==2 & iprov==11
replace j=4 if idepa==2 & iprov==12
replace j=4 if idepa==2 & iprov==13
replace j=4 if idepa==2 & iprov==15
replace j=4 if idepa==2 & iprov==16
replace j=4 if idepa==2 & iprov==17
replace j=4 if idepa==2 & iprov==18
replace j=4 if idepa==2 & iprov==19
replace j=4 if idepa==2 & iprov==20

*5. Arequipa, Moquegua, La Libertad, Lambayeque, Piura, Ica, Tacna, Tumbes
replace j=5 if idepa==4 | idepa==18 | idepa==13 | idepa==14 | idepa==18 | idepa==20 | idepa==11 | idepa==23 | idepa==24

*6. Lima (Oyon, Cajatambo)
replace j=6 if idepa==15 & iprov==9
replace j=6 if idepa==15 & iprov==3

*7. Lima (Huaura, Huarochiri, Huaral, Canta, Barranca)
replace j=7 if idepa==15 & iprov==8
replace j=7 if idepa==15 & iprov==7
replace j=7 if idepa==15 & iprov==6
replace j=7 if idepa==15 & iprov==4
replace j=7 if idepa==15 & iprov==2

* 8. Lima (Lima [Rimac, San Martin de Porres, Villa el Salvador, San Juan de Miraflores])
replace j=8 if idepa==15 & iprov==1 & idist==28
replace j=8 if idepa==15 & iprov==1 & idist==35
replace j=8 if idepa==15 & iprov==1 & idist==42
replace j=8 if idepa==15 & iprov==1 & idist==33

* 9. Lima (Lima [Carabayllo, Miraflores, Magdalena Vieja, Magdalena del Mar, Jesus Maria, Comas, Independencia, El Agustino, 
*Los Olivos, Lince, La Victoria, La Molina, Puente Piedra, Surquillo, Santiago de Surco, Bre.a, Lima, Ate, Villa Maria del Triunfo,
*Santa Anita, San Juan de Lurigancho, San Isidro, San Borja, San Miguel, San Luis,
*San Bartolo]
*replace j=9 if idepa==15 & iprov==1 & j~=8
replace j=9 if idepa==15 & iprov==1 & idist==1
replace j=9 if idepa==15 & iprov==1 & idist==2
replace j=9 if idepa==15 & iprov==1 & idist==3
replace j=9 if idepa==15 & iprov==1 & idist==4
replace j=9 if idepa==15 & iprov==1 & idist==5
replace j=9 if idepa==15 & iprov==1 & idist==6
replace j=9 if idepa==15 & iprov==1 & idist==7
replace j=9 if idepa==15 & iprov==1 & idist==8
replace j=9 if idepa==15 & iprov==1 & idist==9
replace j=9 if idepa==15 & iprov==1 & idist==10
replace j=9 if idepa==15 & iprov==1 & idist==11
replace j=9 if idepa==15 & iprov==1 & idist==12
replace j=9 if idepa==15 & iprov==1 & idist==13
replace j=9 if idepa==15 & iprov==1 & idist==14
replace j=9 if idepa==15 & iprov==1 & idist==15
replace j=9 if idepa==15 & iprov==1 & idist==16
replace j=9 if idepa==15 & iprov==1 & idist==17
replace j=9 if idepa==15 & iprov==1 & idist==18
replace j=9 if idepa==15 & iprov==1 & idist==19
replace j=9 if idepa==15 & iprov==1 & idist==20
replace j=9 if idepa==15 & iprov==1 & idist==21
replace j=9 if idepa==15 & iprov==1 & idist==22
replace j=9 if idepa==15 & iprov==1 & idist==23
replace j=9 if idepa==15 & iprov==1 & idist==24
replace j=9 if idepa==15 & iprov==1 & idist==25
replace j=9 if idepa==15 & iprov==1 & idist==26
replace j=9 if idepa==15 & iprov==1 & idist==27
replace j=9 if idepa==15 & iprov==1 & idist==29
replace j=9 if idepa==15 & iprov==1 & idist==30
replace j=9 if idepa==15 & iprov==1 & idist==31
replace j=9 if idepa==15 & iprov==1 & idist==32
replace j=9 if idepa==15 & iprov==1 & idist==34
replace j=9 if idepa==15 & iprov==1 & idist==36
replace j=9 if idepa==15 & iprov==1 & idist==37
replace j=9 if idepa==15 & iprov==1 & idist==38
replace j=9 if idepa==15 & iprov==1 & idist==39
replace j=9 if idepa==15 & iprov==1 & idist==40
replace j=9 if idepa==15 & iprov==1 & idist==41
replace j=9 if idepa==15 & iprov==1 & idist==43


*10. Lima (Caqete, Yauyos)
replace j=10 if idepa==15 & iprov==5
replace j=10 if idepa==15 & iprov==10

*11. Apurimac, Cusco
replace j=11 if idepa==3 | idepa==8 

*12. Amazonas, Cajamarca, San Martin (Rioja, El Dorado, Moyobamba, Lamas, Huallaga)
replace j=12 if idepa==1
replace j=12 if idepa==6
replace j=12 if idepa==22 & iprov==8
replace j=12 if idepa==22 & iprov==3
replace j=12 if idepa==22 & iprov==1
replace j=12 if idepa==22 & iprov==5
replace j=12 if idepa==22 & iprov==4

*13. San Martin (Picota, Bellavista)
replace j=13 if idepa==22 & iprov==7
replace j=13 if idepa==22 & iprov==2

*14. Huanuco, San Martin (Mariscal Caceres, Tocache)
replace j=14 if idepa==10
replace j=14 if idepa==22 & iprov==6
replace j=14 if idepa==22 & iprov==10

*15. Pasco
replace j=15 if idepa==19

*16. Ayacucho (Parinacochas, Paucar del Sara Sara)
replace j=16 if idepa==5 & iprov==7
replace j=16 if idepa==5 & iprov==8


*17. Ayacucho (Lucanas [Aucara, Chavipa, Chipao, Laramate, Carmen Salcedo, Cabana])
replace j=17 if idepa==5 & iprov==6 & idist==2
replace j=17 if idepa==5 & iprov==6 & idist==5
replace j=17 if idepa==5 & iprov==6 & idist==6
replace j=17 if idepa==5 & iprov==6 & idist==8
replace j=17 if idepa==5 & iprov==6 & idist==4
replace j=17 if idepa==5 & iprov==6 & idist==3

* 18. Ayacucho (Lucanas [San Pedro, Puquio, San Pedro de Palco, Santa Ana de Huaycahuacho, Leoncio Prado, San Juan, Lucanas])
*replace j=18 if idepa==5 & iprov==6 & j~=17
replace j=18 if idepa==5 & iprov==6 & idist==17
replace j=18 if idepa==5 & iprov==6 & idist==1
replace j=18 if idepa==5 & iprov==6 & idist==18
replace j=18 if idepa==5 & iprov==6 & idist==20
replace j=18 if idepa==5 & iprov==6 & idist==9
replace j=18 if idepa==5 & iprov==6 & idist==16
replace j=18 if idepa==5 & iprov==6 & idist==11

*19. Ayacucho (Huanta [Ayahuanco, Huamanguilla, Llochegua])
replace j=19 if idepa==5 & iprov==4 & idist==2
replace j=19 if idepa==5 & iprov==4 & idist==3
replace j=19 if idepa==5 & iprov==4 & idist==8
	
*Ayacucho (Huanta [Huanta])
replace j=20 if idepa==5 & iprov==4 & idist==1
*Assumption
*replace j=20 if idepa==5 & iprov==4 & idist==0
	

*Ayacucho (Huanta [Iguain])
replace j=21 if idepa==5 & iprov==4 & idist==4
*Ayacucho (Huanta [Luricocha])
replace j=22 if idepa==5 & iprov==4 & idist==5

* Ayacucho (Huanta [Santillana])
replace j=23 if idepa==5 & iprov==4 & idist==6

* Ayacucho (Huanta [Sivia])
replace j=24 if idepa==5 & iprov==4 & idist==7

* Ayacucho (La Mar [Chungui, Luis Carranza])
replace j=25 if idepa==5 & iprov==5 & idist==5
replace j=25 if idepa==5 & iprov==5 & idist==6
*Assumption
*replace j=25 if idepa==5 & iprov==5 & idist==0


* Ayacucho (La Mar [San Miguel])
replace j=26 if idepa==5 & iprov==5 & idist==1

* Ayacucho (La Mar [Anco])
replace j=27 if idepa==5 & iprov==5 & idist==2

* Ayacucho (La Mar [Ayna])
replace j=28 if idepa==5 & iprov==5 & idist==3

* Ayacucho (La Mar [Chilcas])
replace j=29 if idepa==5 & iprov==5 & idist==4

* Ayacucho (La Mar [Santa Rosa])
replace j=30 if idepa==5 & iprov==5 & idist==7

* Ayacucho (La Mar [Tambo])
replace j=31 if idepa==5 & iprov==5 & idist==8

* Ayacucho (Cangallo)
replace j=32 if idepa==5 & iprov==2

* Ayacucho (Huanca Sancos)
replace j=33 if idepa==5 & iprov==3

* Ayacucho (Sucre)
replace j=34 if idepa==5 & iprov==9

* Ayacucho (Victor Fajardo)
replace j=35 if idepa==5 & iprov==10

* Ayacucho (Vilcas Huaman)
replace j=36 if idepa==5 & iprov==11

* Ayacucho (Huamanga [Quinua, Ayacucho, Pacaycasa, Jesus Nazareno, Ocros])
replace j=37 if idepa==5 & iprov==1 & idist==8
replace j=37 if idepa==5 & iprov==1 & idist==1
replace j=37 if idepa==5 & iprov==1 & idist==7
replace j=37 if idepa==5 & iprov==1 & idist==15
replace j=37 if idepa==5 & iprov==1 & idist==6
*Assumption
*replace j=37 if idepa==5 & iprov==0 & idist==0
*replace j=37 if idepa==5 & iprov==1 & idist==0



* Ayacucho (Huamanga [Acos Vinchos])
replace j=38 if idepa==5 & iprov==1 & idist==3

* Ayacucho (Huamanga [Carmen Alto])
replace j=39 if idepa==5 & iprov==1 & idist==4

* Ayacucho (Huamanga [Santiago de Pischa, Acocro])
replace j=40 if idepa==5 & iprov==1 & idist==11
replace j=40 if idepa==5 & iprov==1 & idist==2

* Ayacucho (Huamanga [Chiara])
replace j=41 if idepa==5 & iprov==1 & idist==5

* Ayacucho (Huamanga [San Jose de Ticllas])
replace j=42 if idepa==5 & iprov==1 & idist==9

* Ayacucho (Huamanga [San Juan Bautista])
replace j=43 if idepa==5 & iprov==1 & idist==10

* Ayacucho (Huamanga [Socos])
replace j=44 if idepa==5 & iprov==1 & idist==12

* Huancavelica (Huancavelica, Tayacaja, Acobamba, Churcampa)
replace j=45 if idepa==9 & iprov==1 
replace j=45 if idepa==9 & iprov==7
replace j=45 if idepa==9 & iprov==2
replace j=45 if idepa==9 & iprov==5

* Ayacucho (Huamanga [Vinchos])
replace j=46 if idepa==5 & iprov==1 & idist==14


*Puno
replace j=47 if idepa==21

* Huancavelica (Huaytara, Angaraes)
replace j=48 if idepa==9 & iprov==6
replace j=48 if idepa==9 & iprov==3

* Ayacucho (Huamanga [Tambillo])
replace j=49 if idepa==5 & iprov==1 & idist==13

* Huancavelica (Castrovirreyna)
replace j=50 if idepa==9 & iprov==4
	
* Junin (Junin, Tarma, Yauli, Chanchamayo)
replace j=51 if idepa==12 & iprov==5
replace j=51 if idepa==12 & iprov==7
replace j=51 if idepa==12 & iprov==8
replace j=51 if idepa==12 & iprov==3


* Junin (Jauja, Concepcion, Chupaca)
replace j=52 if idepa==12 & iprov==4
replace j=52 if idepa==12 & iprov==2
replace j=52 if idepa==12 & iprov==9

* Junin (Huancayo [Huancayo])
replace j=53 if idepa==12 & iprov==1 & idist==1

* Junin (Huancayo [Chilca])
replace j=54 if idepa==12 & iprov==1  & idist==7

* Junin (Huancayo [El Tambo])
replace j=55 if idepa==12 & iprov==1  & idist==14

* Junin (Huancayo [Chupuro, Huayucachi, Hualhuas, Huacrapuquio, Cullhuas,Huasicancha, Huancan, Colca, Sanyo, Santo Domingo de Acobamba, Viques, Sapallanga, Sicaya, Chicche, Chongos Alto, Carhuacallanga, Ingenio, Pucara, Quichuay, Pariahuanca, SanAgustin, San Jeronimo de Tunan, Chacapampa, Pilcomayo, Quilcas])
*replace j=56 if idepa==12 & iprov==1 & idist~=1 & idist~=7 & idist~=14
replace j=56 if idepa==12 & iprov==1 & idist==11
replace j=56 if idepa==12 & iprov==1 & idist==21
replace j=56 if idepa==12 & iprov==1 & idist==17
replace j=56 if idepa==12 & iprov==1 & idist==16
replace j=56 if idepa==12 & iprov==1 & idist==13
replace j=56 if idepa==12 & iprov==1 & idist==20
replace j=56 if idepa==12 & iprov==1 & idist==19
replace j=56 if idepa==12 & iprov==1 & idist==12
replace j=56 if idepa==12 & iprov==1 & idist==32
replace j=56 if idepa==12 & iprov==1 & idist==35
replace j=56 if idepa==12 & iprov==1 & idist==36
replace j=56 if idepa==12 & iprov==1 & idist==33
replace j=56 if idepa==12 & iprov==1 & idist==34
replace j=56 if idepa==12 & iprov==1 & idist==6
replace j=56 if idepa==12 & iprov==1 & idist==8
replace j=56 if idepa==12 & iprov==1 & idist==4
replace j=56 if idepa==12 & iprov==1 & idist==22
replace j=56 if idepa==12 & iprov==1 & idist==26
replace j=56 if idepa==12 & iprov==1 & idist==27
replace j=56 if idepa==12 & iprov==1 & idist==24
replace j=56 if idepa==12 & iprov==1 & idist==29
replace j=56 if idepa==12 & iprov==1 & idist==30
replace j=56 if idepa==12 & iprov==1 & idist==5
replace j=56 if idepa==12 & iprov==1 & idist==25
replace j=56 if idepa==12 & iprov==1 & idist==28

* Junin (Satipo)
replace j=57 if idepa==12 & iprov==6

* San Martin (San Martin)
replace j=58 if idepa==22 & iprov==9
*Assumption
*replace j=58 if idepa==22 & iprov==0


label variable j "Locations"
label def loca 1 "1 Loreto, Ucayali, Madre de Dios", add
label def loca 2 "2 Callao", add
label def loca 3 "3 Ancash (Orcos, Bolognesi)", add
label def loca 4 "4 Ancash (Rest)", add
label def loca 5 "5 Arequipa, Moquegua, La Libertad, Lambayeque, Piura, Ica, Tacna, Tumbes", add
label def loca 6 "6 Lima (Oyon, Cajatambo)", add
label def loca 7 "7 Lima (Huaura, Huarochiri, Huaral, Canta, Barranca)", add
label def loca 8 "8 Lima (Lima [Rimac, San Martin de Porres, Villa el Salvador, San Juan de Miraflores])", add
label def loca 9 "9 Lima (Lima [Rest])", add
label def loca 10 "10 Lima (Canyete, Yauyos)", add
label def loca 11 "11 Apurimac, Cusco", add
label def loca 12 "12 Amazonas, Cajamarca, San Martin (Rioja, El Dorado, Moyobamba, Lamas, Huallaga)", add
label def loca 13 "13 San Martin (Picota, Bella vista)", add
label def loca 14 "14 Huanuco, San Martin (Mariscal Caceres, Tocache)", add
label def loca 15 "15 Pasco", add
label def loca 16 "16 Ayacucho (Parinacochas, Paucar del Sara Sara)", add
label def loca 17 "17 Ayacucho (Lucanas [Aucara, Chavipa, Chipao, Laramate, Carmen Salcedo, Cabana])", add
label def loca 18 "18 Ayacucho (Lucanas [Rest])", add
label def loca 19 "19 Ayacucho (Huanta [Ayahuanco, Huamanguilla, Llochegua])", add
label def loca 20 "20 Ayachuco (Huanta [Huanta])", add
label def loca 21 "21 Ayacucho (Huanta [Iguain])", add
label def loca 22 "22 Ayacucho (Huanta [Luricocha])", add
label def loca 23 "23 Ayacucho (Huanta [Santillana])", add
label def loca 24 "24 Ayacucho (Huanta [Sivia])", add
label def loca 25 "25 Ayacucho (La Mar [Chungui, Luis Carranza])", add
label def loca 26 "26 Ayacucho (La Mar [San Miguel])", add
label def loca 27 "27 Ayacucho (La Mar [Anco])", add
label def loca 28 "28 Ayacucho (La Mar [Ayna])", add
label def loca 29 "29 Ayacucho (La Mar [Chilcas])", add
label def loca 30 "30 Ayacucho (La Mar [Santa Rosa])", add
label def loca 31 "31 Ayacucho (La Mar [Tambo])", add
label def loca 32 "32 Ayacucho (Cangallo)", add
label def loca 33 "33 Ayacucho (Huanca Sancos)", add
label def loca 34 "34 Ayacucho (Sucre)", add
label def loca 35 "35 Ayacucho (Victor Fajardo)", add
label def loca 36 "36 Ayacucho (Vilcas Huaman)", add
label def loca 37 "37 Ayacucho (Huamanga [Quinua, Ayacucho, Pacaycasa, JNazareno, Orcos])", add
label def loca 38 "38 Ayacucho (Huamanga [Acos Vinchos])", add
label def loca 39 "39 Ayacucho (Huamanga [Carmen Alto])", add
label def loca 40 "40 Ayacucho (Huamanga [Santiago de Pischa, Acocro])", add
label def loca 41 "41 Ayacucho (Huamanga [Chiara])", add
label def loca 42 "42 Ayacucho (Huamanga [San Jose de Ticllas])", add
label def loca 43 "43 Ayacucho (Huamanga [San Juan Bautista])", add
label def loca 44 "44 Ayacucho (Huamanga [Socos])", add
label def loca 45 "45 Huancavelica (Huancavelica, Tayacaja, Acobamba, Churcampa)", add
label def loca 46 "46 Ayacucho (Huamanga [Vinchos])", add
label def loca 47 "47 Puno", add
label def loca 48 "48 Huancavelica (Huaytara, Angaraes)", add
label def loca 49 "49 Ayacucho (Huamanga [Tambillo])", add
label def loca 50 "50 Huancavelica (Castrovirreyna)", add
label def loca 51 "51 Junin (Junin, Tarma, Yauli, Chanchamayo)", add
label def loca 52 "52 Junin (Jauja, Concepcion, Chupaca)", add
label def loca 53 "53 Junin (Huancayo [Huancayo])", add
label def loca 54 "54 Junin (Huancayo [Chilca])", add
label def loca 55 "55 Junin (Huancayo [El Tambo])", add
label def loca 56 "56 Junin (Huancayo [Rest])", add	
label def loca 57  "57 Junin (Satipo)", add
label def loca 58 "58 San Martin (San Martin)", add
label values j loca

************************************************
* Strata done
************************************************
